home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / jamiga001 / bin / TestConstructor.java < prev    next >
Encoding:
Java Source  |  2004-01-31  |  974 b   |  34 lines

  1. import java.lang.reflect.Constructor;
  2.  
  3. class TestConstructor {
  4.     public TestConstructor() {}
  5.  
  6.     private TestConstructor(int i) {}
  7.  
  8.     protected TestConstructor(long l, int i) {}    
  9.  
  10.     public void sayHello() {
  11.         System.out.println("Hello");
  12.     }
  13.  
  14.  
  15.     public static void main(String[] args) throws Exception {
  16.         TestConstructor tc = new TestConstructor();
  17.         System.out.println("Class name: " + tc.getClass().getName());
  18.         Constructor[] c = tc.getClass().getDeclaredConstructors();
  19.         System.out.println("Number of Constructors: " + c.length);
  20.  
  21.         for(int i=0; i<c.length; i++) {
  22.             System.out.println("Method " + i + " modifiers: " + c[i].getModifiers() + " Number of Parameters: " + c[i].getParameterTypes().length);
  23.  
  24.             if(c[i].getParameterTypes().length == 0) {
  25.                 System.out.println("Now trying to instantiate:");
  26.                 Object[] ia = new Object[0];
  27.                 TestConstructor myTC = (TestConstructor)c[i].newInstance(ia);
  28.                 myTC.sayHello();
  29.             }
  30.         }
  31.  
  32.         
  33.     }
  34. }